<?php
class nniValidator extends sfValidatorBase
{
	public function configure($options = array(), $messages = array()) 
    {
        $this->setMessage('invalid', "Le nni n'est pas valide."); 
    }

    public function doClean($valeur)
    {
    //$nni=$_POST['NNI'];
		$nni = $valeur;
		$eFuncs = new erdfFuncs;	
		$personne = $eFuncs->updateFromLDAP($nni);	
				
		/*$q = Doctrine_Query::create()
  			->select('p.id')
  			->from('personnes p')
		  	->where("p.nni = '$nni'");
		$liste=$q->execute();
		$trouve = false;
		foreach($liste as $item )
		{
			$trouve = true;
			$personne=Doctrine::getTable('personnes')->find($item->id);	
		}
		*/
		if($personne)
		{
			return true;
		}
		else
		{
			throw new sfValidatorError($this, 'invalid', array('value' => $nni));
			return false;	
		}
    }
	
}